//
//  WmcPhotoCombineAlertView.swift
//  YPWatermarkCamera
//
//  Created by Json on 2023/7/31.
//

import UIKit

class WmcPhotoCombineAlertView: WmcBaseView, WmcAlertViewProtocol {

    /// stackView
    private lazy var stackView: UIStackView = {
        let stackV = UIStackView()
        stackV.axis = .vertical
        stackV.spacing = 16.0.wmc_autoHor
        stackV.distribution = .fill
        stackV.alignment = .center
        return stackV
    }()
    
    private lazy var imageView: UIImageView = {
        let imgView = UIImageView()
        imgView.image = "icon_id_card_231_319".wmc_image
        return imgView
    }()
    
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = 17.wmc_scaleFont(weight: .medium)
        label.textColor = UIColor.wmc_blackH1_000000
        label.text = "边拍边拼.拍完就拼完"
        return label
    }()
    
    private lazy var msgLabel: UILabel = {
        let label = UILabel()
        label.font = 13.wmc_scaleFont()
        label.textColor = UIColor.wmc_black65
        label.text = "多种样式，一张图片完成所有汇报"
        return label
    }()
    
    private lazy var photoButton: UIButton = {
        let button = UIButton()
        button.backgroundColor = UIColor.wmc_mainTheme
        button.setTitle("马上拍", for: .normal)
        button.setTitleColor(UIColor.wmc_white_FFFFFF, for: .normal)
        button.titleLabel?.font = 17.wmc_scaleFont(weight: .medium)
        button.layer.cornerRadius = 4.0
        button.clipsToBounds = true
        return button
    }()
    
    let photoButtonClicked: PublishRelay<Void> = .init()
    
    
    
    // MARK: UI
    override func makeUI() {
        super.makeUI()
        let vMargin = 16.0.wmc_autoHor
        let imageW = 231.0.wmc_autoHor
        let imageH = 319.0.wmc_autoHor
        let buttonW = 271.0.wmc_autoHor
        let buttonH = 44.0.wmc_autoHor
        layer.cornerRadius = 8.0
        clipsToBounds = true
        // stackView
        addSubview(stackView)
        stackView.snp.makeConstraints { make in
            make.top.equalTo(vMargin)
            make.bottom.equalTo(-vMargin)
            make.left.right.equalToSuperview()
        }
        // 图片
        stackView.addArrangedSubview(imageView)
        imageView.snp.makeConstraints { make in
            make.width.equalTo(imageW)
            make.height.equalTo(imageH)
        }
        // 标题
        stackView.addArrangedSubview(titleLabel)
        // 信息
        stackView.addArrangedSubview(msgLabel)
        // 拍照按钮
        stackView.addArrangedSubview(photoButton)
        photoButton.snp.makeConstraints { make in
            make.width.equalTo(buttonW)
            make.height.equalTo(buttonH)
        }
        
        stackView.setCustomSpacing(6.0.wmc_autoHor, after: titleLabel)
        stackView.setCustomSpacing(24.0.wmc_autoHor, after: msgLabel)
        
    }
    
    // MARK: Bind Action
    
    override func bindViewAction() {
        super.bindViewAction()
        photoButton.rx.tap.subscribe(onNext: {
            [weak self] in
            guard let self = self else { return }
            self.dismiss {
                [weak self] in
                guard let self = self else { return }
                self.photoButtonClicked.accept(())
            }
        }).disposed(by: rx.disposeBag)
    }

}
